package com.squirrel.michale.test04;

import java.util.Arrays;

/**
 * @author guanhao 观浩
 * @version v1.0.0.0
 * @createTime 2023/4/14 19:10
 * @company Michale Squirrel
 * @link
 * @description
 */
public class Exam02 {
    public int[] specialSort(int[] arr1, int[] arr2) {
        int[] numberFrequency = new int[1001];
        int[] resultArray = new int[arr1.length];
        for (int element : arr1) {
            numberFrequency[element]++;
        }
        int resultIndex = 0;
        for (int element : arr2) {
            while (numberFrequency[element] > 0) {
                resultArray[resultIndex++] = element;
                numberFrequency[element]--;
            }
        }
        for (int freqIndex = 0; freqIndex < numberFrequency.length; freqIndex++) {
            while (numberFrequency[freqIndex] > 0) {
                resultArray[resultIndex++] = freqIndex;
                numberFrequency[freqIndex]--;
            }
        }
        return resultArray;
    }

}
